import { Body, Controller, Delete, Get, Param, Patch, Post, Request, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiHeader, ApiOperation, ApiTags } from '@nestjs/swagger';
import { MenuService } from './menu.service';
import { CreateMenuDto } from './dto/create-menu.dto';
import { UpdateMenuDto } from './dto/update-menu.dto';
import { AuthGuard } from '@nestjs/passport';

@ApiBearerAuth() // 需要token
@UseGuards(AuthGuard('jwt'))
@ApiTags('菜单管理')
@ApiHeader({
	name: 'authoriation',
	required: true,
	description: 'token',
})
@Controller({
	path: 'menu',
	version: '1',
})
export class MenuController {
	constructor(private readonly menuService: MenuService) {}

	@ApiOperation({
		tags: ['创建菜单'],
		description: '创建菜单',
	})
	@Post()
	create(@Request() request, @Body() createMenuDto: CreateMenuDto) {
		const { userId } = request.user;
		return this.menuService.create(createMenuDto, userId);
	}

	@Get()
	findAll() {
		return this.menuService.findAll();
	}

	@Get(':id')
	findOne(@Param('id') id: string) {
		return this.menuService.findOne(+id);
	}

	@Patch(':id')
	update(@Param('id') id: string, @Body() updateMenuDto: UpdateMenuDto) {
		return this.menuService.update(+id, updateMenuDto);
	}

	@Delete(':id')
	remove(@Param('id') id: string) {
		return this.menuService.remove(+id);
	}
}
